package com.etms.service;

import com.etms.mapper.CangMapper;
import com.etms.pojo.Customer;
import com.etms.pojo.WareHouse;
import com.etms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CangService {
    @Autowired
    CangMapper cangMapper;
    public List<WareHouse> findWareHouseList() {
        return cangMapper.findList();
    }

    public Result findAll() {
        return Result.successed(findWareHouseList());
    }

    public Result findSuById(Integer id) {
        WareHouse wareHouse=cangMapper.findById(id);
        return Result.successed(wareHouse);
    }

    public Result delSuById(Integer id) {
        int cnt=cangMapper.delById(id);
        if (cnt<=0){
            return Result.failed("莫名错误");
        }
        return Result.successed("删除成功",null);
    }

    public Result updateOrAdd(WareHouse wareHouse) {
        Integer id = wareHouse.getId();
        if (id !=0&& id !=null){//走更新
            int cnt=cangMapper.update(wareHouse);
            if (cnt<=0){
                return Result.failed("莫名失败");
            }
            return Result.successed("更新成功",null);
        }
        int cnt=cangMapper.addOne(wareHouse);//添加
        if (cnt<=0){
            return Result.failed("莫名失败");
        }
        return Result.successed("添加成功",null);
    }
}
